#include "Brassica.h"

class PipeIn;
class PipeOut;

//Pipe class
class Pipe{
private:
	VOID *ReadHead, *WriteHead;
	SIZE_T PageSize;
	HANDLE hMutex;

	VOID *allocatepage();
	VOID freepage(VOID *oldpage);
public:
	PipeIn *inpipe;
	PipeOut *outpipe;
	Pipe(PipeIn **pPipeIn, PipeOut **pPipeOut);
	~Pipe();
	VOID Write(VOID* data, SIZE_T datalen);
	SIZE_T Read(VOID* buffer, SIZE_T maxlen);
};

class PipeEnd {
public: 
	Pipe *pipe;
	PIPEHANDLE hPipe;
};

class PipeIn : public PipeEnd{
public:
	PipeIn(Pipe *BasePipe);
	VOID Write(VOID* data, SIZE_T datalen);
};

class PipeOut : public PipeEnd{       
public:
	PipeOut(Pipe *BasePipe);
	SIZE_T Read(VOID* buffer, SIZE_T maxlen);
};

VOID initpipecontroller();
VOID destroypipecontroller();

VOID createpipe(PIPEHANDLE PipeIn, PIPEHANDLE PipeOut);
VOID destroypipe(PIPEHANDLE hPipeEnd);

